//
//  MYGMeetingListDetailTableViewCell.swift
//  MYDoctor
//
//  Created by 王振明 on 2024/5/13.
//

import UIKit

class MYGMeetingListDetailTableViewCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    var model:MYGMeetingSpeechListModel = MYGMeetingSpeechListModel(){
        didSet{
            timeLabel.text = model.speechTime
            if model.speechCn.count > 0{
                jiangtiLabel.text = model.speechCn
                taskLabel.text = model.expertList.count > 0 ? model.expertList[0].expertRoleCn : ""
                if model.expertList.count == 0{
                    nameLabel.text = ""
                }else if  model.expertList.count == 1{
                    nameLabel.text = model.expertList[0].expertCn
                }else{
                    var str = model.expertList[0].expertCn
                    for item in 1...model.expertList.count - 1 {
                        str = "\(str)\n\(model.expertList[item].expertCn)"
                    }
                    nameLabel.text = str
                }
            }else{
                jiangtiLabel.snp.updateConstraints { make in
                    make.width.equalTo(screenWidth/4*3)
                }
                jiangtiLabel.textAlignment = .left
                if model.expertList.count == 0{
                    jiangtiLabel.text = ""
                }else if  model.expertList.count == 1{
                    jiangtiLabel.text = "\(model.expertList[0].expertRoleCn):\(model.expertList[0].expertCn)"
                }else{
                    var str = model.expertList[0].expertCn
                    for item in 1...model.expertList.count - 1 {
                        str = "\(str),\(model.expertList[item].expertCn)"
                    }
                    jiangtiLabel.text = "\(model.expertList[0].expertRoleCn):\(str)"
                }
//                if model.expertList.count > 0{
//                    var str = model.expertList[0].expertCn
//                    for item in 1...model.expertList.count - 1 {
//                        str = "\(str),\(model.expertList[item].expertCn)"
//                    }
//                    jiangtiLabel.text = "\(model.expertList[0].expertRoleCn):\(str)"
//                }else{
//                    
//                }
            }

        }
    }
    private func configUI(){
        contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        
        contentView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.top.equalToSuperview().offset(15)
            make.width.equalTo(screenWidth/4)
            make.bottom.equalToSuperview().offset(-15)
        }
        
        contentView.addSubview(jiangtiLabel)
        jiangtiLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/4)
            make.top.equalToSuperview().offset(15)
            make.bottom.equalToSuperview().offset(-15)
            make.width.equalTo(screenWidth/4)
        }
        
        contentView.addSubview(taskLabel)
        taskLabel.snp.makeConstraints { make in
            make.width.equalTo(screenWidth/4)
            make.left.equalToSuperview().offset(screenWidth/4*2)
            make.top.equalToSuperview().offset(15)
            make.bottom.equalToSuperview().offset(-15)

        }
        contentView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.width.equalTo(screenWidth/4)
            make.left.equalToSuperview().offset(screenWidth/4*3)
            make.top.equalToSuperview().offset(15)
            make.bottom.equalToSuperview().offset(-15)
        }
        contentView.addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }

    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(0, 66, 241, 1)
        label.font = .medium(12)
        label.textAlignment = .center
        return label
    }()
    private lazy var jiangtiLabel: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(54, 54, 54, 1)
        label.font = .regular(12)
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()
    private lazy var taskLabel: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(54, 54, 54, 1)
        label.font = .regular(12)
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(54, 54, 54, 1)
        label.font = .regular(12)
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()
    private lazy var lineView:UIView = {
       let cont = UIView()
        cont.backgroundColor = .rgba(220, 220, 220, 1)
        return cont
    }()
}
